<?php
class PositionAction extends CommonAction {

	function _filter(&$map) {
		if (!empty($_POST['keyword'])) {
			$map['code|name'] = array('like', "%" . $_POST['keyword'] . "%");
		}
               
	}

       	function save() {
		$opmode = $_POST["opmode"];

		if ($opmode == "add") {
			$this -> insert();
		}
		if ($opmode == "edit") {
			$this -> editdate();
		}
	}
        
        function insert() {
		$model = D('Position');
		if (false === $model -> create()) {
                        echo $model -> getError();
			$this -> error($model -> getError());
                        
		}
                $result = $model -> add();
                
		//保存当前数据对象
		if ($result !== false) {//保存成功
			$this -> assign('jumpUrl', __URL__.'/index/');
			$this -> success('新增成功!');
		} else {
			//失败提示
			$this -> error('新增失败!');
                        $this -> assign('jumpUrl', __URL__.'/index/');
		}
	}
        
        function editdate(){
            $model = D('Position');
            if (false === $model -> create()) {
			$this -> error($model -> getError());
		}
                $result = $model ->save();
                if ($result !== false) {//修改成功
			$this -> assign('jumpUrl', __URL__.'/index/');
			$this -> success('修改成功!');
		} else {
			//失败提示
			$this -> error('修改失败!');
		}
        }

}
?>